<?php
/* @var $this AdvertiseController */
/* @var $model Advertise */
/* @var $form CActiveForm */
?>

<?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'advertise-form',
    'enableAjaxValidation' => false,
    'htmlOptions' => array(
        'role' => 'form',
        'class' => 'form-horizontal',
    )
)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php if ($model->getErrors()) {
    ?>
    <div class="alert alert-error">
        <button class="close" data-dismiss="alert" type="button"> ×</button>
        <?php echo $form->errorSummary($model); ?>
    </div>
<?php } ?>
<div class="form admin-main-wrapper">
    <div class="block block-themed block-last">
        <div class="block-title">
            <h4></h4>
        </div>
        <div class="block-content">
            <div class="row control-group">
                <?php echo $form->labelEx($model, 'name', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 255)); ?>
                </div>
            </div>

            <div class="row control-group">
                <?php echo $form->labelEx($model, 'content', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->textArea($model, 'content', array('rows' => 20, 'cols' => 200, 'id' => 'txtContent')); ?>
                    <div id="characterLeft"></div>
                </div>
            </div>

            <div class="row control-group">
                <?php echo $form->labelEx($model, 'category_id', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->dropDownList($model, 'category_id', CHtml::listData($categories, 'id', 'name')); ?>
                </div>
            </div>

            <div class="row control-group buttons">
                <div class="controls">
                    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class' => 'btn btn-default')); ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->endWidget(); ?>
<script type="text/javascript">
    var $content = $('#txtContent').val().length;
    var max = 274;
    $sub = max - $content;
    if ($sub < 0) {
        $('#characterLeft').text('Đã vượt quá 275 ký tự');
    } else {
        $('#characterLeft').text('Còn lại ' + $sub + ' ký tự');
    }

    $('#txtContent').keyup(function () {

        var len = $(this).val().length;
        if (len == max) {
            $('#characterLeft').text('Đã hết');
        } else if (len > max) {
            $('#characterLeft').text('Đã vượt quá ký tự cho phép');
        } else {
            var ch = max - len;
            $('#characterLeft').text('Còn lại ' + ch + ' ký tự');
        }
    });
</script>
